# -*- coding: utf-8 -*-
"""
-------------------------------------------------
Project Name: luffcity study project
File Name: 定时器.py
Author: kij
Create Date: 2021/3/19
-------------------------------------------------
"""
from threading import Timer
import random
import string


class Code(object):
	def __init__(self):
		self.make_cache()

	def make_cache(self, interval=30):
		self.cache = self.make_code()
		print(self.cache)
		# 第一个参数 定时器事件，第二个方法，第三个 方法里要传入的参数
		self.t = Timer(interval, self.make_cache,args=(5,))
		self.t.start()

	# 创建验证码
	def make_code(self, n=4):
		res = ''
		for i in range(n):
			s1 = str(random.choice(string.digits))
			s2 = str(random.choice(string.ascii_uppercase))
			res += random.choice([s1, s2])
		return res

	def check(self):
		while True:
			code = input('输入你的验证码>>: ').strip()
			print(code)
			print(self.cache)
			print(code.upper() == self.cache)
			if code.upper() == self.cache:
				print('验证码正确')
				self.t.cancel()
				break


obj = Code()
obj.check()
